package com.gthncz;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Demo1 {

    private List<List<Integer>> findZanLang(int M, int N) {
        // 模拟顺时针遍历二维数组, 找到战狼队员
        if (M < 1 || N < 1) return new ArrayList<>();

        List<List<Integer>> result = new ArrayList<>();
        int count = 1;  // 从 1 开始计数

        for (int i=0; 2*i <= M; ++i) {
            int left = i, right = N-i-1;
            int top = i, bottom = M-i-1;

            // 先遍历最上面
            for (int j=left; j<=right; ++j) {
                if (count % 10 == 7 && ((count%100)/10)%2 == 1) {
                    ArrayList<Integer> tuple = new ArrayList<>(2);
                    tuple.add(top);
                    tuple.add(j);
                    result.add(tuple);
                }
                ++count;
            }

            // 遍历右边
            if (bottom > top) {
                for (int j=top+1; j<=bottom; ++j) {
                    if (count % 10 == 7 && ((count%100)/10)%2 == 1) {
                        ArrayList<Integer> tuple = new ArrayList<>(2);
                        tuple.add(j);
                        tuple.add(right);
                        result.add(tuple);
                    }
                    ++count;
                }
            }

            // 遍历底部
            if (bottom > top && right > left) {
                for (int j=right-1; j>= left; --j) {
                    if (count % 10 == 7 && ((count%100)/10)%2 == 1) {
                        ArrayList<Integer> tuple = new ArrayList<>(2);
                        tuple.add(bottom);
                        tuple.add(j);
                        result.add(tuple);
                    }
                    ++count;
                }
            }

            // 遍历左边
            if (bottom > top && left < right) {
                for (int j=bottom-1; j>top; --j) {
                    if (count % 10 == 7 && ((count%100)/10)%2 == 1) {
                        ArrayList<Integer> tuple = new ArrayList<>(2);
                        tuple.add(j);
                        tuple.add(left);
                        result.add(tuple);
                    }
                    ++count;
                }
            }
        }

        return result;
    }

    public static void main(String[] args){
        Demo1 demo = new Demo1();
        Scanner sc = new Scanner(System.in);
        boolean nextLine = false;
        do {
            int M = sc.nextInt();
            int N = sc.nextInt();

            List<List<Integer>> result = demo.findZanLang(M, N);
            List<String> strs = new ArrayList<>(result.size());
            for (List<Integer> item: result){
                String content = "[" + item.get(0) + "," + item.get(1) + "]";
                strs.add(content);
            }
            System.out.printf("[%s]", String.join(",", strs));
        } while ((nextLine = sc.hasNextInt()));
    }


}
